package edu.ut.ece382c.valloy.parser;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.LinkedHashMap;
import java.util.Map;

import java_cup_11a.runtime.Scanner;
import java_cup_11a.runtime.Symbol;

import edu.mit.csail.sdg.alloy4compiler.ast.ExprConstant;
import edu.mit.csail.sdg.alloy4compiler.ast.ExprVar;

public class TestLexer {
	static public void main (String[] filename) throws Exception {
		
		System.out.println(filename[0]);
		
	    Map<Integer,String> ch=new LinkedHashMap<Integer,String>();
	    ch.put(CompSym.ABSTRACT        , "abstract");
	    ch.put(CompSym.ALL             , "all");
	    ch.put(CompSym.ALL2            , "all");
	    ch.put(CompSym.ANY_ARROW_LONE  , "set");
	    ch.put(CompSym.ANY_ARROW_ONE   , "set");
	    ch.put(CompSym.ANY_ARROW_SOME  , "set");
	    ch.put(CompSym.AS              , "as");
	    ch.put(CompSym.ASSERT          , "assert");
	    ch.put(CompSym.BUT             , "but");
	    ch.put(CompSym.CHECK           , "check");
	    ch.put(CompSym.DISJ            , "disj");
	    ch.put(CompSym.EOF             , "eof");
	    ch.put(CompSym.ELSE            , "else");
	    ch.put(CompSym.ENUM            , "enum");
	    ch.put(CompSym.EXACTLY         , "exactly");
	    ch.put(CompSym.EXPECT          , "expect");
	    ch.put(CompSym.EXTENDS         , "extends");
	    ch.put(CompSym.FACT            , "fact");
	    ch.put(CompSym.FOR             , "for");
	    ch.put(CompSym.FUN             , "fun");
	    ch.put(CompSym.ID              , "NAME");
	    ch.put(CompSym.IDEN            , "iden");
	    ch.put(CompSym.IN              , "in");
	    ch.put(CompSym.INT             , "int");
	    ch.put(CompSym.LET             , "let");
	    ch.put(CompSym.LONE            , "lone");
	    ch.put(CompSym.LONE2           , "lone");
	    ch.put(CompSym.LONE_ARROW_ANY  , "lone");
	    ch.put(CompSym.LONE_ARROW_LONE , "lone");
	    ch.put(CompSym.LONE_ARROW_ONE  , "lone");
	    ch.put(CompSym.LONE_ARROW_SOME , "lone");
	    ch.put(CompSym.MODULE          , "module");
	    ch.put(CompSym.NO              , "no");
	    ch.put(CompSym.NO2             , "no");
	    ch.put(CompSym.NONE            , "none");
	    ch.put(CompSym.NUMBER          , "NUMBER");
	    ch.put(CompSym.ONE             , "one");
	    ch.put(CompSym.ONE2            , "one");
	    ch.put(CompSym.ONE_ARROW_ANY   , "one");
	    ch.put(CompSym.ONE_ARROW_LONE  , "one");
	    ch.put(CompSym.ONE_ARROW_ONE   , "one");
	    ch.put(CompSym.ONE_ARROW_SOME  , "one");
	    ch.put(CompSym.OPEN            , "open");
	    ch.put(CompSym.PRED            , "pred");
	    ch.put(CompSym.PRIVATE         , "private");
	    ch.put(CompSym.RUN             , "run");
	    ch.put(CompSym.SEQ             , "seq");
	    ch.put(CompSym.SET             , "set");
	    ch.put(CompSym.SIG             , "sig");
	    ch.put(CompSym.SIGINT          , "Int");
	    ch.put(CompSym.SOME            , "some");
	    ch.put(CompSym.SOME2           , "some");
	    ch.put(CompSym.SOME_ARROW_ANY  , "some");
	    ch.put(CompSym.SOME_ARROW_LONE , "some");
	    ch.put(CompSym.SOME_ARROW_ONE  , "some");
	    ch.put(CompSym.SOME_ARROW_SOME , "some");
	    ch.put(CompSym.SUM             , "sum");
	    ch.put(CompSym.SUM2            , "sum");
	    ch.put(CompSym.THIS            , "this");
	    ch.put(CompSym.UNIV            , "univ");
	    ch.put(CompSym.AMPERSAND       , "&");
	    ch.put(CompSym.AND             , "&&");
	    ch.put(CompSym.ARROW           , "->");
	    ch.put(CompSym.AT              , "@");
	    ch.put(CompSym.BAR             , "|");
	    ch.put(CompSym.CARET           , "^");
	    ch.put(CompSym.COLON           , ":");
	    ch.put(CompSym.COMMA           , ",");
	    ch.put(CompSym.DOMAIN          , "<:");
	    ch.put(CompSym.DOT             , ".");
	    ch.put(CompSym.EQUALS          , "=");
	    ch.put(CompSym.GT              , ">");
	    ch.put(CompSym.GTE             , ">=");
	    ch.put(CompSym.HASH            , "#");
	    ch.put(CompSym.IFF             , "<=>");
	    ch.put(CompSym.IMPLIES         , "=>");
	    ch.put(CompSym.LBRACE          , "{");
	    ch.put(CompSym.LBRACKET        , "[");
	    ch.put(CompSym.LPAREN          , "(");
	    ch.put(CompSym.LT              , "<");
	    ch.put(CompSym.LTE             , "=<");
	    ch.put(CompSym.MINUS           , "-");
	    ch.put(CompSym.NOT             , "!");
	    ch.put(CompSym.NOTEQUALS       , "!");
	    ch.put(CompSym.NOTGT           , "!");
	    ch.put(CompSym.NOTGTE          , "!");
	    ch.put(CompSym.NOTIN           , "!");
	    ch.put(CompSym.NOTLT           , "!");
	    ch.put(CompSym.NOTLTE          , "!");
	    ch.put(CompSym.OR              , "||");
	    ch.put(CompSym.PLUS            , "+");
	    ch.put(CompSym.PLUSPLUS        , "++");
	    ch.put(CompSym.RANGE           , ":>");
	    ch.put(CompSym.RBRACE          , "}");
	    ch.put(CompSym.RBRACKET        , "]");
	    ch.put(CompSym.RPAREN          , ")");
	    ch.put(CompSym.SHL             , "<<");
	    ch.put(CompSym.SHR             , ">>>");
	    ch.put(CompSym.SHA             , ">>");
	    ch.put(CompSym.SLASH           , "/");
	    ch.put(CompSym.STAR            , "*");
	    ch.put(CompSym.TILDE           , "~");
	    ch.put(CompSym.CLASS           , "class");
	    ch.put(CompSym.VIRTUAL         , "virtual");
	    ch.put(CompSym.SUPER           , "super");
	    
	    
		// Scanner lexer = new CompLexer(new BufferedReader(new FileReader(filename[0])));
		Scanner lexer = new CompFilter(new CompLexer(new BufferedReader(new FileReader(filename[0]))));
		
		while(true)
		{
			final Symbol s = lexer.next_token();
			
			if (ch.containsKey(s.sym))
			{
				System.out.println("token : " + ch.get(s.sym));
			}
			else
			{
				System.out.println("unmapped symbol : " + s.sym);
			}
			
			if (s.sym == CompSym.ID)
			{
				System.out.println("   " + ((ExprVar)s.value).label);
			}
			
			if (s.sym == CompSym.NUMBER)
			{
				System.out.println("   " + ((ExprConstant)s.value).num);
			}
			
			if (s.sym == CompSym.EOF)
			{
				break;
			}
		}
	}
}
